package com.zy.edu.controller;


import com.aliyuncs.vod.model.v20170321.CreateUploadVideoResponse;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoResponse;
import com.zy.edu.bean.*;
import com.zy.edu.config.ali.AliVideo;
import com.zy.edu.service.CourseChapterVideoService;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author HuangHaiShui
 * @since 2021-07-24
 */
@RestController
@RequestMapping("/video")
public class CourseChapterVideoController {
    @Resource
    CourseChapterVideoService courseChapterVideoService;

    /**
     * @Author: HuangHaiShui
     * @Description: 数据的新增与修改
     * @Date: 9:17 2021/7/14
     * @param courseChapterVideo:
     * @return: Map
     **/
    @RequestMapping("/edit")
    public Map edit(@Valid CourseChapterVideo courseChapterVideo, InputParam inputParam){
        return courseChapterVideoService.saveOrUpdate(courseChapterVideo,inputParam);
    }
    @RequestMapping("/list")
    public Map list(CourseChapterVideo courseChapterVideo, InputParam inputParam){

        return courseChapterVideoService.list(courseChapterVideo, inputParam);
    }


    /**
     * @Author: HuangHaiShui
     * @Description: 删除数据
     * @Date: 9:18 2021/7/14
     * @param courseChapterVideo:  传入id 字段
     * @return: Map
     **/
    @RequestMapping("/dele")
    public Map dele( CourseChapterVideo courseChapterVideo) throws Exception {
        return courseChapterVideoService.dele(courseChapterVideo);
    }

    //获取视频的信息，以及该视频的播放记录（根据角色，只有老师和学生会触发）
    @RequestMapping("/getById")
    public Map getById(CourseChapterVideo courseChapterVideo, InputParam inputParam){

        return courseChapterVideoService.getById(courseChapterVideo, inputParam);
    }


    //获取视频上传地址和凭证
    @RequestMapping("create")
    public Map createUploadVideoResponse( String title,String fileName  ) throws Exception {
        CreateUploadVideoResponse uploadVideo = AliVideo.createUploadVideo(title,fileName);
        return ResponseInfo.success(uploadVideo);
    }

    // 刷新视频上传凭证
    @RequestMapping("refresh")
    public Map refreshUploadVideoResponse(  String videoId ) throws Exception {
        RefreshUploadVideoResponse refreshUploadVideoResponse = AliVideo.refreshUploadVideo(videoId);
        return ResponseInfo.success(refreshUploadVideoResponse);
    }
    // 获取视频播放地址
    @RequestMapping("getPlayInfo")
    public Map getPlayInfo(  String videoId ) throws Exception {
        GetPlayInfoResponse playInfo = AliVideo.getPlayInfo(videoId);

        return ResponseInfo.success(playInfo);
    }
    // 获取视频认证播放地址
    @RequestMapping("getPlayAuthInfo")
    public Map getPlayAuthInfo(  String videoId ) throws Exception {
        GetVideoPlayAuthResponse playInfo = AliVideo.getPlayAuthInfo(videoId);

        return ResponseInfo.success(playInfo);
    }

    //视频播放记录 班级的 与学生的
    @RequestMapping("saveRecord")
    public Map saveRecord(CourseChapterVideoCls courseChapterVideoCls, InputParam inputParam ) throws Exception {
        return courseChapterVideoService.saveRecord(courseChapterVideoCls, inputParam);

    }
}

